<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('积分增加申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <input name="postList" th:each="p:${post}" th:value="${p}" type="hidden">
                        <ul>
                            <li>
                                <label>类型：</label>
                                <select name="type" th:with="type=${@dict.getType('coin_apply_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('coin_apply_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="btime"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="etime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:apply:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:apply:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:apply:remove')}]];
        var typeDatas = [[${@dict.getType('coin_apply_type')}]];
        var statusDatas = [[${@dict.getType('coin_apply_status')}]];
        var prefix = ctx + "system/apply";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "积分增加申请",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'type', 
                    title: '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'dealerName',
                    title: '门店'
                },
                {
                    field: 'memberName',
                    title: '用户'
                },
                    {
                        field: 'memberCar',
                        title: '姓名',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.name;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '手机号',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.mobile;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '车牌号',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.licensePlate;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '车架号',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.frameNo;
                            }
                        }
                    },
                {
                    field: 'created', 
                    title: '创建时间'
                },
                {
                    field: 'creatorName',
                    title: '申请人'
                },
                {
                    field: 'price',
                    title: '金额'
                },
                {
                    field: 'total',
                    title: '智通币数量'
                },
                {
                    field: 'status', 
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'notes', 
                    title: '备注'
                },
                {
                    field: 'updateUserName',
                    title: '审核人'
                },
                {
                    field: 'updateTime', 
                    title: '审核时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="agree(\'' + row.id + '\')"><i class="fa fa-edit"></i>同意</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="refuse(\'' + row.id + '\')"><i class="fa fa-remove"></i>拒绝</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function agree(id) {
            var a = true;
            layer.confirm('确认通过吗',{
                shade:[0.5,'#000'],
                shift:1,
                shadeClose:true,
                btn:['确认','取消'],
                yes: function (index,layero) {
                    if(a == true){
                        a=false
                        //执行 Ajax 后重载
                        $.ajax({
                            url : prefix+"/agree/"+id,
                            type : "post",
                            success : function(result) {
                                layer.close(index)
                                $.table.search()
                            },
                            error:function () {
                                layer.msg('失败',{'icon':2});
                            }
                        });
                    }else {
                        return;
                    }
                },btn2: function (index,layero) {
                }
            })
        }

        function refuse(id) {
            var a = true;
            layer.confirm('确认拒绝吗',{
                shade:[0.5,'#000'],
                shift:1,
                shadeClose:true,
                btn:['确认','取消'],
                yes: function (index,layero) {
                    if(a == true){
                        a=false
                        //执行 Ajax 后重载
                        $.ajax({
                            url : prefix+"/refuse/"+id,
                            type : "post",
                            success : function(result) {
                                layer.close(index)
                                $.table.search()
                            },
                            error:function () {
                                layer.msg('失败',{'icon':2});
                            }
                        });
                    }else{
                        return;
                    }

                },btn2: function (index,layero) {
                }
            })
        }

    </script>
</body>
</html>